﻿@{
    ViewBag.Title = "过滤IP";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyValue = request('keyValue');
    var objectId = request('objectId');
    var objectType = request('objectType');
    var visitType = request('visitType');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //性别
        $("#F_VisitType").ComboBox({
            description: "==请选择==",
        });
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../AuthorizeManage/FilterIP/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    $("#F_StartIP").val(data.F_IPLimit.split(',')[0]);
                    $("#F_EndIP").val(data.F_IPLimit.split(',')[1]);
                }
            });
        } else {
            $("#F_ObjectId").val(objectId);
            $("#F_ObjectType").val(objectType);
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var StartIP = $("#F_StartIP").val();
        var EndIP = $("#F_EndIP").val();
        if (compareIP(StartIP, EndIP) == -1) {
            ValidationMessage($("#F_EndIP"), "不在同一个网段内");
            return false;
        }
        if (compareIP(StartIP, EndIP) == 0) {
            ValidationMessage($("#F_EndIP"), "结束IP不能大于开始IP");
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["F_IPLimit"] = StartIP + "," + EndIP;
        postData["F_VisitType"] = visitType;
        $.SaveForm({
            url: "../../AuthorizeManage/FilterIP/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                top.FilterIP.$("#gridTable").trigger("reloadGrid");
            }
        })
    }
    //验证IP地址
    function compareIP(ipBegin, ipEnd) {
        var temp1 = ipBegin.split(".");
        var temp2 = ipEnd.split(".");
        if ((temp1[0] + temp1[1] + temp1[2]) == (temp2[0] + temp2[1] + temp2[2])) {
            if (temp2[3] >= temp1[3]) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return -1;//不在同一个网段内
        }
    }
</script>
<div style="margin: 5px;">
    <div class="alert alert-danger" style="margin-bottom: 5px;">
        <i class="fa fa-question-circle" style="position: relative; top: 1px; font-size: 15px; padding-right: 5px;"></i>
        声明：IP地址格式：192.168.0.1；192.168.0.*
    </div>
</div>
<div style="margin-top: 20px; margin-right: 30px;">
    <input id="F_ObjectId" type="hidden" />
    <input id="F_ObjectType" type="hidden" />
    <table class="form">
        <tr>
            <td class="formTitle">起始IP<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="F_StartIP" type="text" class="form-control" isvalid="yes" checkexpession="IsIP" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">结束IP<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="F_EndIP" type="text" class="form-control" isvalid="yes" checkexpession="IsIP" />
            </td>
        </tr>
    </table>

</div>
